#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char ** argv) {
	printf("Wpisz linie które chcesz posortować:\n");
	FILE * sort = popen("sort", "w");
	int count;
	char buffer[1024];
	while ((count = fread(buffer, 1, 1024, stdin)) > 0) {
		if (fwrite(buffer, 1, count, sort) < 0) {
			perror("popen");
			return -1;
		}
	}
	printf("Po sortowaniu:\n");
	fclose(sort);
	return 0;
}
